home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Screenblankers / GBlanker / GSource / BGUI / interface.c next >
C/C++ Source or Header  |  1996-09-26  |  8KB  |  281 lines

  1. #include <exec/memory.h>
  2. #include <dos/dostags.h>
  3. #include <libraries/bgui.h>
  4. #include <libraries/bgui_macros.h>
  5. #include <string.h>
  6.  
  7. #include <clib/bgui_protos.h>
  8. #include <pragmas/bgui_pragmas.h>
  9.  
  10. #include <clib/wb_protos.h>
  11. #include <pragmas/wb_pragmas.h>
  12.  
  13. #include "interface.h"
  14. #include "/includes.h"
  15. #include "/libraries.h"
  16. #include "/protos/protos.h"
  17.  
  18. Object *BlankersLvw, *PrefsBtn, *InfoBtn, *ToggleBtn, *HideBtn;
  19. Object *SettingsBtn, *QuitBtn, *BlankWnd;
  20. struct Window *BlankerWnd;
  21. struct Library *BGUIBase = 0L;
  22. ULONG BGUI_Sigs = 0L;
  23. BYTE Title[128];
  24.  
  25. struct bguiRequest InfoReq = {
  26.     BREQF_CENTERWINDOW|BREQF_LOCKWINDOW|BREQF_AUTO_ASPECT,
  27.     "Garshneblanker", "_OK",
  28.     "Current Tooltype Settings\n\n   BLANKKEY=%s\n   POPKEY=%s\n   TIMEOUT=%ld\n   REPLACE=%s\n   RANDTIMEOUT=%ld\n   BLANKCORNER=%s\n   DONTCORNER=%s",
  29.     0, 0L, '_', 0, 0L, 0L
  30.     };
  31.  
  32. __saveds __asm APTR ResourceHookFunc( register __a0 struct Hook *hook,
  33.                                      register __a2 Object *lv_obj,
  34.                                      register __a1 struct lvResource *lvr )
  35. {
  36.     switch( lvr->lvr_Command )
  37.     {
  38.     case LVRC_MAKE:
  39.         return lvr->lvr_Entry;
  40.     case LVRC_KILL:
  41.         return 0L;
  42.     }
  43. }
  44. struct Hook ResourceHook = {{ 0L, 0L }, ( APTR )ResourceHookFunc, 0L, 0L };
  45.  
  46. __saveds __asm STRPTR DisplayHookFunc( register __a0 struct Hook *hook,
  47.                         register __a2 Object *lv_obj,
  48.                         register __a1 struct lvRender *lvr )
  49. {
  50.     BlankerEntry *Entry = ( BlankerEntry * )lvr->lvr_Entry;
  51.     static BYTE Buffer[80];
  52.     
  53.     if( !Entry->be_Disabled )
  54.         return Entry->be_Name;
  55.  
  56.     strcpy( Buffer, "(" );
  57.     strcat( Buffer, Entry->be_Name );
  58.     strcat( Buffer, ")" );
  59.  
  60.     return Buffer;
  61. }
  62. struct Hook DisplayHook = {{ 0L, 0L }, ( APTR )DisplayHookFunc, 0L, 0L };
  63.  
  64. ULONG ISigs( VOID )
  65. {
  66.     return BGUI_Sigs;
  67. }
  68.  
  69. LONG OpenInterface( VOID )
  70. {
  71.     LONG Rand;
  72.     
  73.     if( BGUIBase )
  74.         return OK;
  75.  
  76.     if(!( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )))
  77.         return QUIT;
  78.  
  79.     Rand = !Stricmp( Prefs->bp_Blanker, "Random" );
  80.  
  81.     strcpy( Title, "Garshneblanker ( PopKey=" );
  82.     strcat( Title, Prefs->bp_PopKey );
  83.     strcat( Title, ", BlankKey=" );
  84.     strcat( Title, Prefs->bp_BlankKey );
  85.     strcat( Title, " )" );
  86.  
  87.     BlankWnd = WindowObject,
  88.     WINDOW_Bounds, &WinBox,
  89.     WINDOW_Title, FilePart( ProgName ),
  90.     WINDOW_ScreenTitle, Title,
  91.     WINDOW_SmartRefresh, TRUE,
  92.     WINDOW_MasterGroup,
  93.     
  94.     VGroupObject,
  95.     HOffset( WHITESPACE ), VOffset( WHITESPACE ), Spacing( 2 ),
  96.     
  97.     StartMember,
  98.         BlankersLvw = ListviewObject,
  99.             GA_ID, ID_BLANKERS,
  100.             LISTV_DisplayHook, &DisplayHook,
  101.             LISTV_ResourceHook, &ResourceHook,
  102.         EndObject,
  103.         Weight( 80 ),
  104.     EndMember,
  105.     
  106.     StartMember,
  107.         HGroupObject,
  108.             Spacing( WHITESPACE ),
  109.             StartMember, PrefsBtn = KeyButton( "_Prefs", ID_PREFS ), EndMember,
  110.             StartMember, InfoBtn = KeyButton( "_Info", ID_INFO ), EndMember,
  111.             StartMember, ToggleBtn = KeyButton( "_Toggle", ID_TOGGLE ), EndMember,
  112.         EndObject,
  113.         Weight( 10 ),
  114.     EndMember,
  115.     
  116.     StartMember,
  117.         HGroupObject,
  118.         Spacing( WHITESPACE ),
  119.             StartMember, HideBtn = KeyButton( "_Hide", ID_HIDE ),
  120.             Weight( 30 ), EndMember,
  121.             StartMember, SettingsBtn = KeyButton( "_Settings", ID_SET ),
  122.             Weight( 40 ), EndMember,
  123.             StartMember, QuitBtn = KeyButton( "_Quit", ID_QUIT ),
  124.             Weight( 30 ), EndMember,
  125.         EndObject,
  126.         Weight( 10 ),
  127.     EndMember,
  128.     
  129.     EndObject,
  130.     
  131.     EndObject;
  132.  
  133.     if( BlankWnd )
  134.     {
  135.         BlankerEntry *Tmp;
  136.         LONG i, Selected;
  137.         
  138.         SetAttrs( PrefsBtn, GA_Disabled, Rand, TAG_END );
  139.         SetAttrs( ToggleBtn, GA_Disabled, Rand, TAG_END );
  140.         GadgetKey( BlankWnd, PrefsBtn, "p" );
  141.         GadgetKey( BlankWnd, InfoBtn, "i" );
  142.         GadgetKey( BlankWnd, ToggleBtn, "t" );
  143.         GadgetKey( BlankWnd, HideBtn, "h" );
  144.         GadgetKey( BlankWnd, SettingsBtn, "s" );
  145.         GadgetKey( BlankWnd, QuitBtn, "q" );
  146.  
  147.         for( i = 0, Tmp = ( BlankerEntry * )BlankerEntries->lh_Head;
  148.             Tmp->be_Node.ln_Succ;
  149.             i++, Tmp = ( BlankerEntry * )Tmp->be_Node.ln_Succ )
  150.         {
  151.             if( !Stricmp( Tmp->be_Name, Prefs->bp_Blanker ))
  152.                 Selected = i;
  153.             BGUI_DoGadgetMethod( BlankersLvw, BlankerWnd, 0L,
  154.                                 LVM_ADDSINGLE, 0L, Tmp, 0L, 0L );
  155.         }
  156.  
  157.         DoMethod( BlankersLvw, BASE_ADDCONDITIONAL, PrefsBtn,
  158.                  LISTV_EntryNumber, NumBlankEntries, GA_Disabled, TRUE,
  159.                  GA_Disabled, FALSE );
  160.         DoMethod( BlankersLvw, BASE_ADDCONDITIONAL, ToggleBtn,
  161.                  LISTV_EntryNumber, NumBlankEntries, GA_Disabled, TRUE,
  162.                  GA_Disabled, FALSE );
  163.  
  164.         SetAttrs( BlankersLvw, LISTV_Select, Selected, TAG_DONE );
  165.  
  166.         if( BlankerWnd = WindowOpen( BlankWnd ))
  167.         {
  168.             GetAttr( WINDOW_SigMask, BlankWnd, &BGUI_Sigs );
  169.             ActivateWindow( BlankerWnd );
  170.             SetAttrs( BlankersLvw, LISTV_Select, Selected, TAG_DONE );
  171.             DoMethod( BlankersLvw, LVM_REFRESH, 0L );
  172.             WindowToFront( BlankerWnd );
  173.             ScreenToFront( BlankerWnd->WScreen );
  174.  
  175.             return OK;
  176.         }
  177.     }
  178.  
  179.     return QUIT;
  180. }
  181.  
  182. VOID CloseInterface( VOID )
  183. {
  184.     GetAttr( WINDOW_Bounds, BlankWnd, ( ULONG * )&WinBox );
  185.     WinBoxToEnv( &WinBox );
  186.     WindowClose( BlankWnd );
  187.     BlankerWnd = 0L;
  188.     BGUI_Sigs = 0L;
  189.     DisposeObject( BlankWnd );
  190.     BlankWnd = 0L;
  191.     CloseLibrary( BGUIBase );
  192.     BGUIBase = 0L;
  193. }
  194.  
  195. LONG HandleInterface( VOID )
  196. {
  197.     LONG RetVal = OK, rc;
  198.  
  199.     if( !BGUIBase )
  200.         return OK;
  201.  
  202.     while (( rc = HandleEvent( BlankWnd )) != WMHI_NOMORE )
  203.     {
  204.         switch ( rc )
  205.         {
  206.         case ID_QUIT:
  207.             RetVal = QUIT;
  208.             break;
  209.         case WMHI_CLOSEWINDOW:
  210.         case ID_HIDE:
  211.             RetVal = CLOSEWIN;
  212.             break;
  213.         case ID_SET:
  214.             if( WBenchMsg &&( SysBase->lib_Version > 38 ))
  215.             {
  216.                 struct Library *WorkbenchBase;
  217.                 
  218.                 if( WorkbenchBase = OpenLibrary( "workbench.library", 39L ))
  219.                 {
  220.                     struct Screen *PubScr;
  221.                     
  222.                     if( PubScr = LockPubScreen( 0L ))
  223.                     {
  224.                         WBInfo( WBenchMsg->sm_ArgList->wa_Lock,
  225.                                WBenchMsg->sm_ArgList->wa_Name, PubScr );
  226.                         UnlockPubScreen( 0L, PubScr );
  227.                         RetVal = RESTART;
  228.                     }
  229.                     CloseLibrary( WorkbenchBase );
  230.                 }
  231.             }
  232.             else
  233.             {
  234.                 BGUI_Request( BlankerWnd, &InfoReq, Prefs->bp_BlankKey,
  235.                              Prefs->bp_PopKey, Prefs->bp_Timeout / 10,
  236.                              Prefs->bp_Flags & BF_REPLACE ? "YES" : "NO",
  237.                              Prefs->bp_RandTimeout / 10,
  238.                              CornerStrs[Prefs->bp_BlankCorner],
  239.                              CornerStrs[Prefs->bp_DontCorner] );
  240.             }
  241.             break;
  242.         case ID_TOGGLE:
  243.         {
  244.             BlankerEntry *Entry;
  245.  
  246.             Entry = ( BlankerEntry * )DoMethod( BlankersLvw, LVM_FIRSTENTRY,
  247.                                                0L, LVGEF_SELECTED );
  248.                         ToggleModuleDisabled( Prefs );
  249.             Entry->be_Disabled = !Entry->be_Disabled;
  250.             DoMethod( BlankersLvw, LVM_REFRESH, 0L );
  251.             break;
  252.         }
  253.         case ID_PREFS:
  254.             if( Stricmp( Prefs->bp_Blanker, "Random" ))
  255.                 ExecSubProc( "PrefInterp", "" );
  256.             break;
  257.         case ID_INFO:
  258.             ExecSubProc( "ShowInfo", ".txt" );
  259.             break;
  260.         case ID_BLANKERS:
  261.         {
  262.             BlankerEntry *Entry;
  263.     
  264.             MessageModule( "GarshneClient", BM_DOQUIT );
  265.             MessageModule( "GarshnePrefs", BM_DOQUIT );
  266.             Entry = ( BlankerEntry * )DoMethod( BlankersLvw, LVM_FIRSTENTRY,
  267.                                                0L, LVGEF_SELECTED );
  268.             strcpy( Prefs->bp_Blanker, Entry->be_Name );
  269.             if( Stricmp( Prefs->bp_Blanker, "Random" ))
  270.                 LoadModule( Prefs->bp_Dir, Prefs->bp_Blanker );
  271.             BlankerToEnv( Prefs );
  272.             break;
  273.         }
  274.         default:
  275.             break;
  276.         }
  277.     }
  278.  
  279.     return RetVal;
  280. }
  281.